'use strict';

const checktoken = require("./middleware/checktoken");

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
    const { router, controller } = app;
    //前端接口
    router.get('/', controller.home.index);
    router.get("/book", controller.book.getBookList)
    router.get("/chapter/:id",controller.chapter.getChapter)
    router.get("/section/:id",controller.section.getSectionDetail)
    router.get("/blog", controller.blog.getBlogList)
    router.get("/blogDetail/:id", controller.blog.getBlogDetail)
    router.get("/video", controller.video.getVideoList)
    router.get("/videoDetail/:id",controller.video.getVideoDetail)
    router.get("/resource", controller.resources.getResourceList)

    //后台接口
    router.post("/api/login", controller.admin.login)
    router.resources("book", "/api/book",app.middleware.checktoken(),controller.book)
    router.resources("blog", "/api/blog",app.middleware.checktoken(), controller.blog)
    router.resources("video", "/api/video",app.middleware.checktoken(), controller.video)
    router.resources("resource", "/api/resource",app.middleware.checktoken(), controller.resources)
    router.resources("chapter", "/api/chapter",app.middleware.checktoken(), controller.chapter)
    router.resources("section", "/api/section",app.middleware.checktoken(),controller.section)
    router.resources("user", "/api/user",controller.user)
    router.post("/api/upload",controller.upload.index)
    router.delete("/api/unlink/:target",controller.unLink.index)
};